<!-- Good be like is a Requirement Statistics Gulp table -->
<template>
  <ContainerLayout class="requirement-statistics">
    <div class="form-container">
      <el-form ref="formRef" :inline="true" :model="queryForm" class="query-form" label-width="40px">
        <el-form-item>
          <el-radio-group v-model="showType" @change="handleChangeShowType">
            <el-radio-button v-for="item in tableTypeList" :key="item.value" :label="item.label" v-bind:value="item.value" />
          </el-radio-group>
        </el-form-item>
        <el-form-item label="用户">
          <el-input v-model="queryForm.user" clearable placeholder="请输入" style="width: 100px" />
        </el-form-item>
        <el-form-item label="部门">
          <el-cascader :options="deptList" :props="deptProps" style="width: 290px" v-model="queryForm.deptIds" collapse-tags clearable />
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="queryForm.timelogCategory" placeholder="选择" style="width: 80px">
            <el-option label="全部" value="" />
            <el-option v-for="item in projectTypes" :key="item.dictCode" :label="`${item.dictLabel}`" :value="item.dictValue" />
          </el-select>
        </el-form-item>
        <el-form-item label="项目" v-if="queryForm.timelogCategory === '0'">
          <el-select v-model="queryForm.projectId" placeholder="请选择项目" style="width: 160px">
            <el-option v-for="item in projectList" :key="item.code" :label="`${item.code}-${item.cname}`" :value="item.id" />
          </el-select>
        </el-form-item>
        <TimeSlotDatePicker label="时段" v-model="queryForm.date" />
        <el-form-item>
          <el-button type="primary" @click="handleClickBtnSubmit" :icon="Search">查询</el-button>
          <el-button @click="handleClickBtnReset" :icon="Refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-container">
      <template v-if="isQueryed">
        <template v-if="tableData.length">
          <div class="table-title">{{ projectTitle }}</div>
          <div class="table-wrap" ref="tableWrap">
            <el-table ref="dataTable" stripe scrollbar-always-on :data="tableData" style="width: 100%" border :span-method="tableSpanMethod" :summary-method="getSummaries" show-summary :height="tableHeight" header-cell-class-name="table-header-row" empty-text="没有数据">
              <el-table-column prop="deptName" label="部门" width="150" fixed />
              <el-table-column prop="userName" label="用户" width="120" fixed>
                <template #default="scope">
                  {{ scope.row.userNick }}
                </template>
              </el-table-column>
              <el-table-column label="类型" width="80" fixed>
                <template #default="scope">
                  {{ scope.row.timelogCategoryName }}
                </template>
              </el-table-column>
              <el-table-column label="项目" width="210" fixed>
                <template #default="scope"> {{ scope.row.projectName }} - {{ scope.row.projectCode }} </template>
              </el-table-column>
              <el-table-column label="百分比" width="80" fixed>
                <template #default="scope">{{ showTableColumnTotal(scope.row) }} </template>
              </el-table-column>
              <el-table-column label="总时长" width="80" fixed>
                <template #default="scope">{{ showTableColumnTotal2(scope.row) }} </template>
              </el-table-column>
              <el-table-column label="任务名" width="90" fixed>
                <template #default="scope">{{ scope.row.taskName }} </template>
              </el-table-column>
              <el-table-column label="任务类型" width="90" fixed>
                <template #default="scope">{{ scope.row.taskCategory }} </template>
              </el-table-column>
              <template v-for="item in tableColumnDate">
                <el-table-column :prop="item.label" width="80" resizable>
                  <template #header>
                    <div class="table-header-cell">
                      <div>{{ item.label }}</div>
                      <!-- <div>{{ item.end }}</div> -->
                    </div>
                  </template>
                  <template #default="scope">
                    {{ scope.row[item.columnName + ':val'] }}
                  </template>
                </el-table-column>
              </template>
              <el-table-column />
            </el-table>
          </div>
        </template>
        <template v-else>
          <div class="table-title" v-if="projectTitle !== ''">{{ projectTitle }}</div>
          <el-empty description="没有查询到符合条件的数据" />
        </template>
      </template>
      <template v-else>
        <el-empty description="尚未查询数据" />
      </template>
    </div>
  </ContainerLayout>
</template>
<script setup lang="ts">
import ContainerLayout from '../layout/ContainerLayout.vue'
// import type { VNode } from 'vue'
import { reactive, ref, nextTick, onMounted, computed, h } from 'vue'
import { useDeptStore, useProjectssStore, useTaskTypeStore, useUsersStore, useFormSearchDataStore } from '../stores'
import IProjectTypes from '../interface/IProjectTypes'
import { Refresh, Search } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import http from '../http'
import * as utils from '../utils'
import TimeSlotDatePicker from '../layout/FormTableLayout/TimeSlotDatePicker.vue'
// import { useRouter, useRoute } from 'vue-router'

// 工作时长
const workingHours = ref(0)
const deptStore = useDeptStore()
const projectssStore = useProjectssStore()
const queryForm = reactive({
  user: '',
  projectId: '',
  date: [] as Date[],
  deptIds: [] as string[] | number[],
  timelogCategory: '',
})
const deptProps = ref({ multiple: true, label: 'deptName', value: 'deptId' })
const deptList = ref(deptStore.getAllState())
const projectTypes = ref<IProjectTypes[]>(useTaskTypeStore().getAllState())
const projectList = ref<Array<{ id: number; code: string; cname: string }>>(projectssStore.getAllState() as any)
// 显示类型 0: 人/周 1: 人/天
const showType = ref(0)
const tableData = ref<any[]>([])
const tableColumnDate = ref<any[]>([])
const tableWrap = ref<HTMLElement | null>(null)
const tableHeight = ref(500)
const dataTable = ref(null)
const projectTitle = ref<string>('')
const weeks = ref<any[]>([])
const isQueryed = ref(false)
const dataResult = ref()

const rowsProjectTime = ref<any[]>([])
const rowsUserTotal = ref<any[]>([])
const rowsHeadcount = ref<any[]>([])
const rowTotalheadcount = ref<any[]>([])

/**
 * 异步获取数据
 *
 * @param startTimelogDate 开始时间
 * @param endTimelogDate 结束时间
 * @returns 返回数据行
 */
const fetchData = async (startTimelogDate: any, endTimelogDate: any) => {
  projectTitle.value = `${startTimelogDate} - ${endTimelogDate} ${currentShowTypeItem.value.label} 项目统计`
  const params = {
    startTimelogDate,
    endTimelogDate,
  }
  const deptIds: any[] = []
  queryForm.deptIds.forEach((e: any) => {
    deptIds.push(e[e.length - 1])
  })
  if (queryForm.user !== '') {
    Object.assign(params, { userName: queryForm.user })
  }
  if (deptIds.length > 0) {
    Object.assign(params, { deptIds: deptIds.join(',') })
  }
  if (queryForm.timelogCategory !== '') {
    Object.assign(params, { timelogCategory: queryForm.timelogCategory })
  }
  if (queryForm.timelogCategory === '0' && queryForm.projectId !== '') {
    Object.assign(params, { projectId: queryForm.projectId })
    const projectItem = projectList.value.find((e: any) => e.id == queryForm.projectId)
    if (projectItem) {
      projectTitle.value = `${projectItem.code}-${projectItem.cname} ` + projectTitle.value
    }
  }
  if (queryForm.timelogCategory === '0' && queryForm.projectId === '') {
    ElMessage.error('必须选择项目')
    return
  }
  const res = await http({
    method: 'GET',
    path: currentShowTypeItem.value.path,
    params,
  })
  const { rows } = res
  return rows
}
/**
 * 异步获取数据
 *
 * @param startTimelogDate 开始时间
 * @param endTimelogDate 结束时间
 * @returns 返回数据行
 */
const fetchDataRowTotalByPath = async (startTimelogDate: any, endTimelogDate: any, path: string) => {
  const params = {
    startTimelogDate,
    endTimelogDate,
  }
  const deptIds: any[] = []
  queryForm.deptIds.forEach((e: any) => {
    deptIds.push(e[e.length - 1])
  })
  if (queryForm.user !== '') {
    Object.assign(params, { userName: queryForm.user })
  }
  if (deptIds.length > 0) {
    Object.assign(params, { deptIds: deptIds.join(',') })
  }
  if (queryForm.timelogCategory !== '') {
    Object.assign(params, { timelogCategory: queryForm.timelogCategory })
  }
  if (queryForm.timelogCategory === '0' && queryForm.projectId !== '') {
    Object.assign(params, { projectId: queryForm.projectId })
    const projectItem = projectList.value.find((e: any) => e.id == queryForm.projectId)
    if (projectItem) {
      projectTitle.value = `${projectItem.code}-${projectItem.cname} ` + projectTitle.value
    }
  }
  if (queryForm.timelogCategory === '0' && queryForm.projectId === '') {
    ElMessage.error('必须选择项目')
    return
  }
  const res = await http({
    method: 'GET',
    path,
    params,
  })
  const { rows } = res
  return rows
}
/**
 * 根据项目类型值获取项目类型名称
 *
 * @param val 项目类型值
 * @returns 返回项目类型名称，若未找到则返回空字符串
 */
const getProjectTypesName = (val: string) => {
  const item = projectTypes.value.find((e) => e.dictValue == val)
  if (item) {
    return item.dictLabel
  } else {
    return ''
  }
}
/**
 * 获取部门周统计数据
 *
 * 此函数用于请求部门的周统计数据，可以帮助管理人员了解部门在一周内的工作量、进度或其他关键指标
 * 该函数目前未实现具体逻辑，需要根据后端接口文档添加请求代码
 */
const getDepartmentWeeklyStats = async () => {
  if (queryForm.date.length == 2) {
    const [start, end] = queryForm.date
    console.log('111 start', utils.formatDate(new Date(start), 'yyyy-MM-dd'))
    console.log('111 end', utils.formatDate(new Date(end), 'yyyy-MM-dd'))
    // console.log(projectList.value)
    // const showTypeItem = tableTypeList.value[showType.value]

    if (currentShowTypeItem.value) {
      weeks.value = utils.getWeeksBetweenDates2(start, end)
      // const [first] = weeks.value
      // const [last] = weeks.value.slice(-1)
      const startTimelogDate = utils.formatDate(new Date(start), 'yyyy-MM-dd')
      const endTimelogDate = utils.formatDate(new Date(end), 'yyyy-MM-dd')

      // 设置 table 列
      tableColumnDate.value = [
        ...weeks.value.map((e) => {
          const start = utils.formatDate(e.start, 'yyyy-MM-dd')
          const end = utils.formatDate(e.end, 'yyyy-MM-dd')
          const startYear = utils.formatDate(e.start, 'yyyy')
          const endYear = utils.formatDate(e.end, 'yyyy')
          const startDay = utils.formatDate(e.start, 'MM-dd')
          const endDay = utils.formatDate(e.end, 'MM-dd')
          return { label: start, columnName: `${start} - ${end}`, start, end, startDay, endDay, startYear, endYear }
        }),
      ]
      // minutes 每天工作时长 （长春 400 分钟）
      // 一周 5 天
      // const weekMinutes = minutes * 5 // 一周 工作 5 天 时长

      const rows = await fetchData(startTimelogDate, endTimelogDate)
      // 百分比单元格
      rowsProjectTime.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listprojecttime')
      // 用户总时长 比单元格
      rowsUserTotal.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listusertotal')
      // 合计 总百分比
      rowsHeadcount.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listheadcount')
      // 合计 单元格
      rowTotalheadcount.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listusertotalheadcount')

      const result: any = {}
      rows.forEach((row: any) => {
        const key = `${row.deptId}-${row.userName}-${row.timelogCategory}-${row.projectCode}`
        if (!result[key]) {
          result[key] = {
            ...row,
            total: 0,
            timelogCategoryName: getProjectTypesName(row.timelogCategory),
          }
          // result[key] = {
          //   deptId: row.deptId,
          //   userName: row.userName,
          //   userNick: row.userNick,
          //   deptName: row.deptName,
          //   timelogCategory: row.timelogCategory,
          //   projectName: row.projectName,
          //   projectCode: row.projectCode,
          // }
        }

        const dateRange = `${row.weekStartDate} - ${row.weekEndDate}`
        result[key][dateRange] = row.durationTime
        result[key][row.weekStartDate] = row.durationTime
      })
      for (const key in result) {
        const e = result[key]
        for (let index = 0; index < tableColumnDate.value.length; index++) {
          const temp = tableColumnDate.value[index]
          if (!e[temp.columnName]) {
            e[temp.columnName] = 0
          }
          const colVal = e[temp.columnName] // ( e[temp.columnName] * 1000) / workingHours.value / currentShowTypeItem.value.days
          e[temp.start] = colVal
          e[temp.columnName] = colVal
          e[temp.columnName + ':val'] = colVal // utils.formatNumber(colVal / 1000)
        }
      }
      await bindDataToTable(Object.values(result))
    }
  }
}

/**
 * 获取部门每日统计数据
 *
 * 该函数用于请求并获取部门级别的每日统计数据这通常包括部门的人数、出勤情况、工作量等信息
 * 统计数据可以帮助管理层了解部门的运营状况和效率，以便做出相应的决策和调整
 *
 */
const getDepartmentDailyStats = async () => {
  if (queryForm.date.length == 2) {
    const [start, end] = queryForm.date
    console.log('start', utils.formatDate(new Date(start), 'yyyy-MM-dd'))
    console.log('end', utils.formatDate(new Date(end), 'yyyy-MM-dd'))
    const startTimelogDate = utils.formatDate(new Date(start), 'yyyy-MM-dd')
    const endTimelogDate = utils.formatDate(new Date(end), 'yyyy-MM-dd')
    const days = utils.generateDates(start, end)

    if (currentShowTypeItem.value) {
      // 设置 table 列
      tableColumnDate.value = [
        ...days.map((e) => {
          return { label: e, columnName: e, start: e }
        }),
      ]
      const rows = await fetchData(startTimelogDate, endTimelogDate)
      // 百分比单元格
      rowsProjectTime.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listprojecttime')
      // 用户总时长 比单元格
      rowsUserTotal.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listusertotal')
      // 合计 总百分比
      rowsHeadcount.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listheadcountday')
      // 合计 单元格
      rowTotalheadcount.value = await fetchDataRowTotalByPath(startTimelogDate, endTimelogDate, '/dev-api/oa/timelog/listusertotalheadcount')

      const result: any = {}
      rows.forEach((row: any) => {
        const key = `${row.deptId}-${row.userName}-${row.timelogCategory}-${row.projectCode}`
        if (!result[key]) {
          result[key] = {
            ...row,
            total: 0,
            timelogCategoryName: getProjectTypesName(row.timelogCategory),
          }
          // result[key] = {
          //   deptId: row.deptId,
          //   userName: row.userName,
          //   deptName: row.deptName,
          //   userNick: row.userNick,
          //   timelogCategory: row.timelogCategory,
          //   projectName: row.projectName,
          //   projectCode: row.projectCode,
          //   total: 0,
          // }
        }
        if (!result[key][row.timelogDate]) {
          result[key][row.timelogDate] = row.durationTime
        } else {
          result[key][row.timelogDate] += row.durationTime
        }
        result[key].total += row.durationTime
        // result[row.deptId][row.timelogDate].total = row.durationTime + result[row.deptId][row.timelogDate].total
      })

      for (const key in result) {
        const e = result[key]
        for (let index = 0; index < tableColumnDate.value.length; index++) {
          const temp = tableColumnDate.value[index]
          if (!e[temp.columnName]) {
            e[temp.columnName] = 0
          }
          const colVal = e[temp.columnName] // (e[temp.columnName] * 1000) / workingHours.value / currentShowTypeItem.value.days
          e[temp.start] = colVal
          e[temp.columnName] = colVal
          // (每周工作时长 [ 为取整 × 1000 ] )
          // 每周工作时长 / minutes 每天工作时长 （长春 400 分钟）/ 1 天 [ 为还原 ÷ 1000 ]
          e[temp.columnName + ':val'] = colVal // utils.formatNumber(colVal / 1000)
        }
        // (每周总工作时长 [ 为取整 × 1000 ] )
        // 每周总工作时长 / minutes 每天工作时长 （长春 400 分钟）/ 1 天 [ 为还原 ÷ 1000 ]
        // const totalVal = (e.total * 1000) / workingHours.value / currentShowTypeItem.value.days / 1000
        // e['total:val'] = utils.formatNumber(totalVal)
      }
      await bindDataToTable(Object.values(result))
    }
  }
}

const showTableColumnTotal2 = (val: any) => {
  if (val) {
    const { timelogCategory, userName, projectName } = val
    let item: any = null
    if (projectName) {
      item = rowsUserTotal.value.find((e: any) => e.projectName == projectName && e.timelogCategory == timelogCategory && e.userName == userName)
    } else {
      item = rowsUserTotal.value.find((e: any) => e.userName == userName && e.timelogCategory == timelogCategory)
    }
    if (item) {
      return item.durationTime
    }
  }
}
const showTableColumnTotal = (val: any) => {
  if (val) {
    const { timelogCategory, userName, projectName } = val
    let item: any = null
    if (projectName) {
      item = rowsProjectTime.value.find((e: any) => {
        if (e.projectName == projectName && e.timelogCategory == timelogCategory && e.userName == userName) {
          return e
        }
      })
    } else {
      item = rowsProjectTime.value.find((e: any) => {
        if (e.userName == userName && e.timelogCategory == timelogCategory) {
          return e
        }
      })
    }
    if (item) {
      return item.durationTime + '%'
    }
    // console.log('rowsProjectTime', rowsProjectTime.value)
    // console.log('rowsHeadcount', rowsHeadcount.value)
  }
}

const tableTypeList = ref([
  { label: '周', value: 0, days: 5, path: '/dev-api/oa/timelog/listbyuserweek', queryMethod: getDepartmentWeeklyStats },
  { label: '天', value: 1, days: 1, path: '/dev-api/oa/timelog/listbyuserday', queryMethod: getDepartmentDailyStats },
])

/**
 * 根据名称和索引统计数量
 *
 * @returns 返回一个对象，键为首次出现的索引，值为一个数组，包含名称出现的次数和标志位1
 */
const countByNameAndIndex = (data: any[]) => {
  const nameCountMap: { [key: string]: number } = {}
  const firstIndexMap: { [key: string]: number } = {}
  data.forEach((item: any, index) => {
    if (!nameCountMap[item.userName]) {
      nameCountMap[item.userName] = 1
      firstIndexMap[item.userName] = index
    } else {
      nameCountMap[item.userName]++
    }
  })

  const mergedObject: { [key: string]: Array<number> } = {}
  for (const name in nameCountMap) {
    mergedObject[firstIndexMap[name]] = [nameCountMap[name], 1]
  }
  // console.log('mergedObject firstIndexMap', firstIndexMap)
  // console.log('mergedObject nameCountMap', nameCountMap)
  // console.log('mergedObject tableData', tableData)
  // console.log('mergedObject B', mergedObject)
  return mergedObject
}

/**
 * 对象跨列方法
 *
 * @param row 行对象
 * @param column 列对象
 * @param rowIndex 行索引
 * @param columnIndex 列索引
 * @returns 返回一个数组，表示该单元格应横跨的列数和行数
 */
const tableSpanMethod = ({ rowIndex, columnIndex }: any) => {
  if (columnIndex <= 1) {
    let res = dataResult.value[rowIndex]
    if (res) {
      return res
    } else {
      return [0, 0]
    }
  }
}

/**
 * 将数据绑定到表格中
 *
 * @param data 要绑定到表格的数据
 * @returns 无返回值
 */
const bindDataToTable = async (data: any) => {
  dataResult.value = await countByNameAndIndex(data)
  // console.log('dataResult', dataResult.value)
  tableData.value = data
  nextTick(() => {
    const tableWrapElement = tableWrap.value
    if (tableWrapElement) {
      // 设置表格高度
      tableHeight.value = tableWrapElement.offsetHeight
      // 延迟执行，等待表格渲染完成后再设置
      // setTimeout(() => {
      //   if (tableWrapElement) {
      //     // 表格的最后一行前两个单元格合并
      //     const tds = tableWrapElement.querySelectorAll('.el-table__footer td')
      //     const tbs0 = tds[0] as HTMLElement
      //     tbs0.setAttribute('colspan', '5')
      //     tbs0.style.textAlign = 'center'
      //     tds[1].remove()
      //     tds[2].remove()
      //     tds[3].remove()
      //     tds[4].remove()
      //   }
      // }, 200)
    }
  })
}

/**
 * 切换显示类型
 *
 * @param index 显示类型的索引
 * @returns {void}
 */
const currentShowTypeItem = computed(() => tableTypeList.value[showType.value])

/**
 * 提交表单处理函数
 *
 * @returns {Promise<void>} 返回一个异步操作的Promise对象，无返回值
 */
const handleClickBtnSubmit = async () => {
  // console.log('queryForm.date', queryForm.date)
  isQueryed.value = true
  tableData.value = []
  projectTitle.value = ''
  useFormSearchDataStore().setAllState({
    startDate: utils.formatDate(new Date(queryForm.date[0]), 'yyyy-MM-dd'),
    endDate: utils.formatDate(new Date(queryForm.date[1]), 'yyyy-MM-dd'),
  })
  if (queryForm.date.length == 2) {
    await tableTypeList.value[showType.value].queryMethod()
  }
}

/**
 * 重置按钮点击事件处理函数
 *
 * @returns 无返回值
 */
const handleClickBtnReset = async () => {
  await resetForm()
}
/**
 * 计算表格数据中的汇总信息
 *
 * @param param 包含表格列信息和数据的对象
 * @returns 返回汇总信息的数组，每个元素可能是字符串或VNode，表示该列的汇总结果
 */
const getSummaries = (param: any) => {
  const { columns, data } = param
  const sums: any[] = []
  columns.forEach((column: any, index: number) => {
    if (index === 0) {
      sums[index] = h('div', { class: 'total-headcount', style: 'width:270px;' }, ['Total Headcount'])

      return
    }
    // if (index === 4) {
    //   sums[index] = rowTotalheadcount.value[0].durationTime * 100 + '%'
    //   return
    // }
    if (index === 5) {
      sums[index] = rowTotalheadcount.value[0].durationTime
      return
    }
    // console.log('rowsHeadcount', rowsHeadcount.value)
    const values = data.map((item: any) => Number(item[column.property]))
    // sums[index] = '0'
    if (!values.every((value: any) => Number.isNaN(value))) {
      let item: any = null
      if (showType.value === 1) {
        item = rowsHeadcount.value.find((item: any) => item.timelogDate === column.property)
      } else if (showType.value === 0) {
        item = rowsHeadcount.value.find((item: any) => item.weekStartDate === column.property)
      }

      //
      if (item) {
        sums[index] = item.durationTime
      } else {
        sums[index] = '0'
      }
      // sums[index] = values.reduce((prev: any, curr: any) => {
      //   const value = Number(curr)
      //   if (!Number.isNaN(value)) {
      //     return prev + curr
      //   } else {
      //     return prev
      //   }
      // }, 0)
    } else {
      sums[index] = ''
    }
  })
  // 去掉第一列和最后一列的汇总信息，第一列是部门名称，最后一列是占位，不需要计算
  for (let index = 1; index < sums.length - 1; index++) {
    // 每周工作时长 / minutes 每天工作时长 （长春 400 分钟）/ 5 一周 5 天 [ 为还原 ÷ 1000 ]
    // sums[index] = ((sums[index] as number) * 1000) / workingHours.value / currentShowTypeItem.value.days / 1000
    sums[index] = sums[index] as number // (sums[index] as number) / 1000
  }
  sums[1] = ''
  // console.log(' ====== ', new Date().getTime())
  // console.log('data', data)
  // console.log('sums', sums)
  return sums
}

/**
 * 重置表单
 *
 * 重置查询表单的所有字段到初始状态，包括用户、项目ID、日期范围、部门ID数组和时间日志类别
 */
const resetForm = () => {
  isQueryed.value = false
  tableData.value = []
  projectTitle.value = ''
  const [start, end] = utils.getDateRangeByDate2(utils.shortcutsType.本月) as Date[]
  queryForm.user = ''
  queryForm.projectId = ''
  queryForm.date = [start, end]
  const formSearchData = useFormSearchDataStore().getAllState()
  // console.log('formSearchData', formSearchData)
  if (formSearchData) {
    queryForm.date = [formSearchData.startDate, formSearchData.endDate]
  }
  queryForm.deptIds = [] as string[] | number[]
  queryForm.timelogCategory = ''
}
/**
 * 处理显示类型改变的方法
 *
 * @async
 */
const handleChangeShowType = async () => {
  await resetForm()
  await handleClickBtnSubmit()
}
onMounted(async () => {
  const { minutes } = useUsersStore().getAllState() as any // 获取每天工作时长
  workingHours.value = minutes

  await resetForm()
  // await handleClickBtnSubmit()
  // await initDate()
})
</script>

<style lang="scss" scoped>
.requirement-statistics {
  display: flex;
  flex-direction: column;
  .form-container {
    display: flex;
    justify-content: flex-start;
  }
  .table-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    .table-wrap {
      flex: 1;
    }
  }
}
.table-header-cell {
  writing-mode: vertical-lr;
  // line-height: 1;
}
</style>
